import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:getwidget/colors/gf_color.dart';
import 'package:getwidget/components/avatar/gf_avatar.dart';
import 'package:getwidget/components/bottom_sheet/gf_bottom_sheet.dart';
import 'package:getwidget/components/button/gf_button.dart';
import 'package:getwidget/components/list_tile/gf_list_tile.dart';

import '../controllers/gfbottomsheet_controller.dart';

class GfbottomsheetView extends GetView<GfbottomsheetController> {
  final GFBottomSheetController _controller = GFBottomSheetController();
  String avatarPath = 'assets/images/cliu.jpg';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('底部弹窗'),
        centerTitle: true,
      ),
      body: Container(
        margin: EdgeInsets.all(10),
        child: ListView(
          children: [
            GFListTile(
              avatar: GFAvatar(
                backgroundImage: AssetImage(avatarPath),
              ),
              titleText: '初六',
              subTitleText: '懂二进制的男人',
            ),
          ],
        ),
      ),
      bottomSheet: _renderBottomSheetTwo(),
      floatingActionButton: Obx(() {
        return FloatingActionButton(
          backgroundColor: GFColors.SUCCESS,
          child: controller.isOpend.value 
          ? Icon(Icons.keyboard_arrow_down)
          : Icon(Icons.keyboard_arrow_up),
          onPressed: () {
            print(_controller.isBottomSheetOpened);
            controller.isOpend.value = _controller.isBottomSheetOpened;
            controller.isOpend.value
            ? _controller.hideBottomSheet()
            : _controller.showBottomSheet();
          }
        );
      })
      
    );
  }

  Widget _renderBottomSheetOne() {
    return GFBottomSheet(
      controller: _controller,
      maxContentHeight: 150,
      stickyHeaderHeight: 80,
      stickyHeader: Container(
        decoration: BoxDecoration(
          color: Colors.purple.shade100,
          boxShadow: [BoxShadow(color: Colors.black87, blurRadius: 0)]
        ),
        child: GFListTile(
          avatar: GFAvatar(
            backgroundImage: AssetImage(avatarPath),
          ),
          titleText: '初六',
          subTitleText: '懂二进制的男人',
        ),
      ),
      contentBody: Container(
        height: 200,
        margin: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
        child: ListView(
          shrinkWrap: true,
          physics: const ScrollPhysics(),
          children: const [
            Center(
              child: Text(
                'Getwidget reduces your overall app development time to minimum 30% because of its pre-build clean UI widget that you can use in flutter app development. We have spent more than 1000+ hours to build this library to make flutter developer’s life easy.',
                style: TextStyle(
                  fontSize: 15, 
                  wordSpacing: 0.3, 
                  letterSpacing: 0.2
                ),
              )
            )
          ],
        ),
      ),
      stickyFooter: Container(
        color: GFColors.SUCCESS,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: [
            Text(
              'Get in touch',
              style: TextStyle(
                fontSize: 15,
                fontWeight: FontWeight.bold,
                color: Colors.white
              ),
            ),
            Text(
              'whoicliu@163.com',
              style: TextStyle(fontSize: 15, color: Colors.white),
            ),
          ],
        ),
      ),
      stickyFooterHeight: 50,
    );
  }

  Widget _renderBottomSheetTwo() {
    return GFBottomSheet(
      controller: _controller,
      maxContentHeight: 300,
      // enableExpandableContent: true,
      stickyHeaderHeight: 80,
      stickyHeader: Container(
        decoration: BoxDecoration(
          color: Colors.orange.shade100,
          boxShadow: [BoxShadow(color: Colors.black45, blurRadius: 0)]
        ),
        child: GFListTile(
          avatar: GFAvatar(
            backgroundImage: AssetImage(avatarPath),
          ),
          titleText: '初六',
          subTitleText: '懂二进制的男人',
        ),
      ),
      contentBody: SingleChildScrollView(
        child: Container(
          margin: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
          child: Column(
            children: [
              Container(
                margin: EdgeInsets.symmetric(horizontal: 15),
                child: Row(
                  children: <Widget>[
                    Container(
                      width: 30,
                      height: 30,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(50),
                        image: DecorationImage(
                          image: AssetImage(avatarPath)
                        )
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.only(left: 6),
                      child: Text(
                        'Add to your story',
                        style: TextStyle(color: Colors.blue),
                      )
                    )
                  ],
                ),
              ),
              ListView.builder(
                physics: ScrollPhysics(),
                shrinkWrap: true,
                scrollDirection: Axis.vertical,
                itemCount: 3,
                itemBuilder: (BuildContext context, int index) {
                  return SingleChildScrollView(
                    child: InkWell(
                      child: GFListTile(
                        avatar: GFAvatar(
                          backgroundImage: AssetImage(avatarPath),
                          size: 20,
                        ),
                        subTitleText: 'John Mendez',
                        icon: Container(
                          width: 66,
                          height: 30,
                          child: GFButton(
                            onPressed: () {},
                            color: GFColors.PRIMARY,
                            child: Center(
                              child: Text(
                                'Send',
                                style: TextStyle(color: Colors.white),
                              )
                            ),
                          ),
                        ),
                      ),
                    )
                  );
                }
              ),
            ],
          ),
        ),
      ),
    );
  }
}
